package org.example.workQueues;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import org.example.utils.RabbitMqUtils;

/**
 * @author zfj
 * @date 2022/4/22 -13:48
 */
public class Worker01 {
	//队列名称
	private static final String QUEUE_NAME="hello";

	//接收消息
	public static void main(String[] args) throws Exception {
		Channel channel = RabbitMqUtils.getChannel();
		DeliverCallback deliverCallback=(consumerTag, delivery)->{
			String receivedMessage = new String(delivery.getBody());
			System.out.println("接收到消息:"+receivedMessage);
		};
		CancelCallback cancelCallback=(consumerTag)->{
			System.out.println(consumerTag+"消费者取消消费接口回调逻辑");
		};
		System.out.println("C2 消费者启动等待消费......");
		/**
		 * 消费者消费消息
		 * 1.消费哪个队列
		 * 2.消费成功后是否要自动应答，false代表手动应答
		 * 3.消费者未成功消费的回调
		 * 4.消费者取消消费的回调
		 */
		channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
	}
}
